package com.pentajock.docdb.types;


public class WeightedUser extends User {
	private int weight;
	/*
	 * private constructor called from public one below.
	 * WeightedUsers should always be created from an
	 * existing User reference so that it can grab
	 * it's information including its properties.
	 */
	private WeightedUser(String userName,
							String firstName,
							String lastName,
							String departmentName,
							boolean isAdmin,
							boolean isSupervisor,
							int weight) {
		super(userName, firstName, lastName, departmentName, isAdmin, isSupervisor);
	}
	
	public WeightedUser(User u, int weight) {
		this(u.getUserName(),
			 u.getFirstName(),
			 u.getLastName(),
			 u.getDepartmentName(),
			 u.isAdmin(),
			 u.isSupervisor(),
			 weight
		);
		this.weight = weight;
	}
	
	public int getWeight() {
		return weight;
	}
	
	public boolean weightEquals(int weight) {
		return this.weight == weight;
	}
	
	public boolean equals(Object o) {
		if(o != null && o instanceof WeightedUser) {
			WeightedUser other = (WeightedUser)o;
			return getWeight() == other.getWeight() && getFullName().equals(other.getFullName());
		}
		return false;
	}
	
	public int compareTo(User u) {
		// check weights.
		if(u instanceof WeightedUser) {
			WeightedUser wu = (WeightedUser)u;
			if(getWeight() < wu.getWeight()) {
				return 1;     
			}
			if(getWeight() > wu.getWeight()) {
				return -1;
			}
		}
		// same weight, use documentName's compareTo;
		return getFullName().compareTo(u.getFullName());
	}
}
